package com.ali.ttt.netty.client.listener;

import com.ali.ttt.netty.common.domain.ApiMessage;
import com.ali.ttt.netty.common.domain.LoginRes;
import com.ali.ttt.netty.common.domain.Message;
import com.ali.ttt.netty.common.intface.InMessage;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * @author yuxl
 */
@Slf4j
@Component
public class ClientListener {
    @InMessage(path="/api",name = "调用api")
    public void api(Message<ApiMessage> req){
        log.info("调用api");
    }

    @InMessage(path="/msg",name = "接收到字符串消息")
    public void msg(Message<String> req){
        log.info("接收到字符串消息:{}",req);
    }

    @InMessage(path="/login",name = "登录响应")
    public void login(Message<LoginRes> req){
        LoginRes msg = req.getMsg();
        if(msg.isSuccess()){
            log.info("登陆成功,id:{}",msg.getSId());
        }else{
            log.info("登陆失败:{}",msg.getMsg());
        }
    }
}
